<?php
/**
 * Control content for static portion of site
 *  
 * author: Chris Lunsford
 **/
class ContentModel extends Model {
	
	function __construct() {
		parent::__construct();
	}
	
	function createBIYL($post) {
		$this->db->insert('cms_biyl', $post);
	}
	
	function deleteBIYL($id) {
		$this->db->where('id', $id);
		$this->db->delete('cms_biyl');
	}
	
	function updateBIYL($id, $post) {
		$this->db->where('id', $id);
		$this->db->update('cms_biyl', $post);
	}
	
	function getBIYL($id) {
		$this->db->where('id', $id);
		return $this->db->get('cms_biyl')->row();
	}
	
	function getBIYLs() {
		return $this->db->get('cms_biyl');
	}
	
	function createPrayer($post) {
		$this->db->insert('cms_prayer', $post);
	}
	
	function createPrayerReply($post) {
		$this->db->insert('cms_prayer_reply', $post);
	}
	
	function deletePrayer($id) {
		$this->db->where('id', $id);
		$this->db->delete('cms_prayer');
	}
	
	function updatePrayer($id, $post) {
		$this->db->where('id', $id);
		$this->db->update('cms_prayer', $post);
	}
	
	function getPrayer($id) {
		$this->db->where('id', $id);
		return $this->db->get('cms_prayer')->row();
	}
	
	function getPrayers() {
		$this->db->select('substring(prayer,1,20) as prayer,length(prayer) as prayerLength,email,id,date,anonymous',false);
		$this->db->orderby('date','asc');
		return $this->db->get('cms_prayer');
	}
	
	function createPodcast($post) {
		$this->db->insert('cms_podcasts', $post);
	}
	
	function deletePodcast($id) {
		$this->db->where('id', $id);
		$this->db->delete('cms_podcasts');
	}
	
	function updatePodcast($id, $post) {
		$this->db->where('id', $id);
		$this->db->update('cms_podcasts', $post);
	}
	
	function getPodcast($id) {
		$this->db->where('id', $id);
		return $this->db->get('cms_podcasts')->row();
	}
	
	function getPodcasts() {
		$this->db->order_by('uploaded desc');
		return $this->db->get('cms_podcasts');
	}
	
	function createAnnouncement($post) {
		$this->db->insert('cms_announcements', $post);
	}
	
	function deleteAnnouncement($id) {
		$this->db->where('id', $id);
		$this->db->delete('cms_announcements');
	}
	
	function updateAnnouncement($id, $post) {
		$this->db->where('id', $id);
		$this->db->update('cms_announcements', $post);
	}
	
	function getAnnouncement($id) {
		$this->db->where('id', $id);
		return $this->db->get('cms_announcements')->row();
	}
	
	function getAnnouncements() {
		return $this->db->get('cms_announcements');
	}
	
	function getCurrentAnnouncements() {
		$this->db->where('expires >', time());
		$this->db->orwhere('expires', '0');
		return $this->db->get('cms_announcements');
	}
	
	function createContent($post) {
		$this->db->insert('cms_content', $post);
	}
	
	function deleteContent($key) {
		$this->db->where('key', $key);
		$this->db->delete('cms_content');
	}
	
	function updateContent($key, $value) {
		$this->db->where('key', $key);
		$this->db->set('value', $value);
		$this->db->update('cms_content');
	}
	
	function getContent($key) {
		$this->db->where('key', $key);
		return $this->db->get('cms_content')->row();
	}
	
	function getAllContent() {
		return $this->db->get('cms_content');
	}	
}
?>
